import { createLogger } from './logging'

const logger = createLogger('assert')

let assertionErrorShown = false;

function initAssert(){
  /**
   * 期待一个True，如果不为True就将报错
   * @param {Boolean} condition 
   * @param  {...String} failureMessage 
   */
  window.assert = function(condition, ...failureMessage){
    if(!condition){
      logger.error('assertion failed:', ...failureMessage);
      if(!assertionErrorShown){
        assertionErrorShown = true;
      }
      throw new Error('AssertionError: ' + failureMessage.join(' '));
    }
  }
}

initAssert();